public class  UpdateOppSalesTeam
{
    public static void updatesalesteam(Id opp)
    {
        List<OpportunityTeamMember> lstUpdateoppTeam=new List<OpportunityTeamMember>();
        List<OpportunityTeamMember> lstDeloppTeam=new List<OpportunityTeamMember>();
        ID AASRecordTypeID = RecordTypeHelper.GetRecordTypeID('Opportunity', 'Advanced Ad Solutions');
        List<Opportunity> lstopp=[select id,RecordTypeId,OwnerId,Post_Sale_Manager__c from opportunity where id=:opp];
        system.debug('testing12'+lstopp);
        Map<Id,OpportunityTeamMember> mapoppteam=new Map<Id,OpportunityTeamMember>();
        List<OpportunityTeamMember> lstoppTeam=[Select TeamMemberRole,OpportunityId,OpportunityAccessLevel From OpportunityTeamMember where OpportunityId=:opp];
        system.debug('testing123'+lstUpdateoppTeam);
        for(OpportunityTeamMember OppTeam:lstoppTeam)
        {       
                if(lstopp[0].RecordtypeId==AASRecordTypeID)
                {
                    if(OppTeam.TeamMemberRole=='Seller')
                    {
                    OpportunityTeamMember tm=OppTeam.clone(false,true,false,false);
                    tm.UserId = lstopp[0].OwnerId;
                    lstDeloppTeam.add(OppTeam);
                    lstUpdateoppTeam.add(tm);
                    }
                    else if(OppTeam.TeamMemberRole=='Sales Planner' && lstopp[0].Post_Sale_Manager__c!=null)
                    {
                    OpportunityTeamMember team=OppTeam.clone(false,true,false,false);
                    team.UserId =lstopp[0].Post_Sale_Manager__c;
                    lstDeloppTeam.add(OppTeam);
                    lstUpdateoppTeam.add(team);
                    }
                }
                
            
        }
        system.debug('testing'+lstUpdateoppTeam);
        delete lstDeloppTeam;
        insert lstUpdateoppTeam;
        
        system.debug('testing1'+lstUpdateoppTeam);
    }
}